<!DOCTYPE html>
<head>
    <#assign dicSelect = JspTaglibs["http://www.casic304.cn/dicSelect"]/>
    <#assign secSelect = JspTaglibs["http://www.casic304.cn/secSelect"] />
    <#assign fillDept=JspTaglibs["http://www.casic304.cn/fillDept"] />
    <meta charset="utf-8">
    <title>获奖管理基本信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/style/qbdms.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body class="listBody">
<div class="qbdms-bodyDiv">
    <div class="layui-table-view-body qbdms-add-view-body">
        <form class="formPreview layui-form" requrl="${ctx}/qbdms/wQbdAwardInformation/get" lay-filter="wQbdAwardInformationDataForm">
            <div class="qbdms-formTitle">获奖信息 <i class="qbdms-returnOn closeWindow">返回</i></div>
            <div class="qbdms-formBody">
                <@fillDept.dept id="tbxx"/>
                <div class="layui-row">
                    <div class="qbdms-oneForm">
                        <label class="layui-form-label qbdms-label" title="个人/单位">个人/单位<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <@dicSelect.dic name="awardOrg" nodeKey="grdw" verify="required" reqtext="个人/单位是必选项" filter="awardOrg"/>
                        </div>
                    </div>
                    <div class="qbdms-oneForm" id="awardDeptTd">
                        <label class="layui-form-label qbdms-label" title="获奖单位">获奖单位</label>
                        <div class="layui-input-block qbdms-input">
                            <input type="text" placeholder="自动带入" autocomplete="off" class="layui-input isReadonlyInput" name="awardDept" maxlength="50" readonly>
                        </div>
                    </div>
                    <div class="qbdms-oneForm">
                        <label class="layui-form-label qbdms-label" title="获奖人">获奖人</label>
                        <button type="button" class="layui-btn qbdms-twoBtn" id="selectAwardPersonBtn">选择</button>
                        <div class="layui-input-block qbdms-input qbdms-inputIsButton">
                            <input type="text" placeholder="请选择" autocomplete="off" class="layui-input textInput" name="awardPerson" maxlength="50" readonly>
                        </div>
                    </div>
                    <div class="qbdms-oneForm">
                        <label class="layui-form-label qbdms-label" title="密级">密级<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <@secSelect.sec_select data_src=1 required=true name="secret"/>
                        </div>
                    </div>
                    <div class="qbdms-oneForm">
                        <label class="layui-form-label qbdms-label" title="工作单位">工作单位</label>
                        <div class="layui-input-block qbdms-input">
                            <input type="text" placeholder="自动带入" autocomplete="off" class="layui-input isReadonlyInput" name="workDept" maxlength="50" readonly>
                        </div>
                    </div>
                    <div class="qbdms-oneForm">
                        <label class="layui-form-label qbdms-label" title="获奖名称">获奖名称<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <input type="text" placeholder="请输入" autocomplete="off" class="layui-input " lay-verify="required" name="awardName" lay-reqtext="获奖名称是必填项" maxlength="50">
                        </div>
                    </div>
                    <div class="qbdms-oneForm">
                        <label class="layui-form-label qbdms-label" title="奖项类别">奖项类别<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <@dicSelect.dic name="awardType" nodeKey="jxlb" verify="required" reqtext="奖项类别是必选项"/>
                        </div>
                    </div>
                    <div class="qbdms-oneForm">
                        <label class="layui-form-label qbdms-label" title="年度">年度<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <input type="text" placeholder="请输入" class="layui-input " lay-verify="required" name="years" id="years" lay-reqtext="年度是必填项" maxlength="50" readonly>
                        </div>
                    </div>
                    <div class="qbdms-oneForm">
                        <label class="layui-form-label qbdms-label" title="获奖时间">获奖时间<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <input type="text" placeholder="请输入" autocomplete="off" class="layui-input dateTimeFiled input-right time-init" name="awardDate" format="yyyy-MM-dd" datetype="date" lay-verify="required" lay-reqtext="获奖时间是必选项" readonly>
                        </div>
                    </div>
                    <div class="qbdms-oneForm">
                        <label class="layui-form-label qbdms-label" title="获奖等级">获奖等级<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <input type="text" name="awardGrade" placeholder="请输入" autocomplete="off" class="layui-input  textInput" maxlength="50" lay-verify="required" lay-reqtext="获奖等级是必填项">
                        </div>
                    </div>
                    <div class="qbdms-oneForm">
                        <label class="layui-form-label qbdms-label" title="授奖单位">授奖单位<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <@dicSelect.dic name="grantDept" nodeKey="sjdw" verify="required" reqtext="授奖单位是必选项"/>
                        </div>
                    </div>
                    <div class="qbdms-oneForm">
                        <label class="layui-form-label qbdms-label" title="评定阶段">评定阶段<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <@dicSelect.dic name="stage" nodeKey="pdjd" verify="required" reqtext="评定阶段是必选项"/>
                        </div>
                    </div>
                    <div class="qbdms-oneForm">
                        <label class="layui-form-label qbdms-label" title="证书编号">证书编号<span style="color: red;">*</span></label>
                        <div class="layui-input-block qbdms-input">
                            <input type="text" placeholder="请输入" autocomplete="off" class="layui-input " lay-verify="required" name="certificateNo" lay-reqtext="证书编号是必填项" maxlength="50">
                        </div>
                    </div>
                    <div class="qbdms-textarea">
                        <label class="layui-form-label qbdms-label" title="获奖原因">获奖原因</label>
                        <div class="layui-input-block qbdms-input">
                            <textarea rows="2" class="layui-textarea" placeholder="请输入" name="awardReason" maxlength="50"></textarea>
                        </div>
                    </div>
                    <div class="qbdms-oneForm">
                        <label class="layui-form-label qbdms-label" title="奖励金额（元）">奖励金额（元）</label>
                        <div class="layui-input-block qbdms-input">
                            <input type="text" placeholder="请输入" autocomplete="off" class="layui-input " lay-verify="money" name="awardAmount" maxlength="10">
                        </div>
                    </div>
                    <div class="qbdms-textarea">
                        <label class="layui-form-label qbdms-label">相关证明文件</label>
                        <div class="layui-input-block qbdms-input">
                            <div class="doNotDelThisDiv layui-input-inline">
                                <div class="uploadFileCont">
                                    <input type="button" class="layui-btn iconfont iconupload fileUpload qbdms-fileUp" value="上传附件"/>
                                    <i class="qbdms-fileUpText">支持多附件上传，附件格式：doc docx pdf，文件大小限制不超过100M</i>
                                    <input type="text" id="certificateFile" class="uploadInput" name="certificateFile" style="display: none">
                                    <div class="uploadFileList" fileUploadName="certificateFile"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-hide">
                <input type="text" name="id" placeholder="请输入" autocomplete="off" class="layui-input " maxlength="50" fieldname="id">
                <input type="text" name="awardDeptCode" placeholder="请输入" autocomplete="off" class="layui-input  textInput" maxlength="50" fieldname="awardDeptCode">
                <input type="text" name="awardPersonId" placeholder="请输入获奖人id" autocomplete="off" class="layui-input  textInput" maxlength="50" fieldname="awardPersonId">
                <input type="text" name="workDeptCode" placeholder="请输入工作单位ID" autocomplete="off" class="layui-input  textInput" maxlength="50" fieldname="workDeptCode">
                <input type="text" name="grantDeptCode" placeholder="请输入" autocomplete="off" class="layui-input  textInput" maxlength="50" fieldname="grantDeptCode">
            </div>
            <div class="layui-form-item btnformItem">
                <p>
                    <span id="hideAndShow" style="display: none;">
                        <a lay-submit lay-filter="wQbdTeamExpertact" class="layui-btn btn-n privateSubmit qbdms-oneBtn" requrl="${ctx}/qbdms/wQbdAwardInformation/save">提交</a>
                    </span>
                    <button type="reset" id="closeWindow" style="margin-left: 10px;" class="layui-btn layui-btn-sm btn-save qbdms-oneBtnLine">取消</button>
                </p>
            </div>
        </form>
    </div>
</div>

<script src="${ctx}/qbdmsStatic/public/configFile.js"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    layui.config({
        base: serverPath.qbdmsPath + staticPath.qbdmsPath //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'setter', 'layer', 'propsHandle', 'upload', 'common', 'laydate', 'jquery', 'publicMethods', 'commonDialog', 'qbdmsForm'], function () {

        // -----常量声明----------
        var $ = layui.jquery,
            laydate = layui.laydate,
            setter = layui.setter,  // 配置信息
            layer = layui.layer,
            common = layui.common,
            propsHandle = layui.propsHandle,
            upload = layui.upload,
            publicMethods = layui.publicMethods,
            formId = '${formDefId}' || '',
            commonDialog = layui.commonDialog,
            defProps = {
                //viewMould: 'form/formDef/view/formDesign/moulds/', // 组件模块 存放文件 *****
                viewMould: 'moulds/', // 组件模块 存放文件 *****
                formAreaInfo: '.formPreview',
                formAreaInfo: 'html',
                temDate: '.temDate',
                uploadFileBtn: '.uploadFileBtn',
                uploadImgBtn: '.uploadImgBtn',
                richTextArea: '.richTextArea',
                selectInput: '.selectInput',
                radioOptionCont: '.radioOptionCont',
                dataLexiTree: '.dataLexiTree',
                selectorBtn: '.selectorBtn'
            },
            temQuery = new propsHandle(),  // 实例化模板功能部分
            form = layui.qbdmsForm;
        // 初始化模板功能
        temQuery.initTem({
            selectorBtn: defProps.selectorBtn,
            selectorTemPath: setter.views + defProps.viewMould
        });
        $(".subContTem").hide()
        // 子表初始化事件
        temQuery.initSubEvent(defProps, serverPath, setter);

        var dateTimeFiledLen = $(".dateTimeFiled");
        for (var i = 0; i < dateTimeFiledLen.length; i++) {
            laydate.render({
                elem: dateTimeFiledLen[i] //指定元素
                , type: 'date'
                , trigger: 'click'
            });
        }

        //年选择器
        laydate.render({
            elem: '#years'
            , type: 'year'
            , trigger: 'click'
        });

        //关闭当前页面
        $("#closeWindow,.closeWindow").click(function () {
            window.location.href = serverPath.qbdmsPath + '/qbdms/wQbdAwardInformation/view/list';
        });

        form.verify({
            money: function (value, item) {
                if (value && !new RegExp(/^((0{1}\.\d{1,2})|([1-9]\d*\.{1}\d{1,2})|([1-9]+\d*)|0)$/).test(value)) {
                    return common.verifyTitleAdd(item) + "请输入数字且小数最多两位";
                }
            }
        });

        var runId = "${runId}";
        if (runId == null || runId == '') {
            $("#hideAndShow").show();
        }
        var secSelect = '<@secSelect.sec_select data_src=1 hasBlank=false/>'
        common.uploadfun(".fileUpload", {
            acceptMime: '${wjszsdsxlx}',
            exts: "${fileManagementUploadType}",
            secSelect: secSelect,
            isSub: false,
            upLoadSize: 102400,
            isMultiFile: true,
            upLoadNumber: 0
        });
        common.updateForm({
            name: 'wQbdAwardInformationDataForm',
            idValue: "${id}",
            primary: "id",
            beforeSubmitFun: function (data) {
                //- 附件密级不能高于表单密级 开始 ------------------------------------------------------
                var selectMaxVal = 0;
                var formSecretVal = $("[name='secret']").val();
                $(".fileSecLevel select").each(function () {
                    selectMaxVal = selectMaxVal >= $(this).val() ? selectMaxVal : $(this).val();
                });

                if (selectMaxVal > formSecretVal) {
                    layer.msg('附件密级不能高于表单密级。', {icon: 5});
                    return false;
                }
                //- 附件密级不能高于表单密级 结束 ------------------------------------------------------
                $(".uploadFileList").each(function (i, v) {
                    common.constructFileStr(v)
                });
                var files = [];
                //整理上传附件的隐藏域，将提交的字符串转为json对象
                $(".uploadInput").each(function () {
                    var uploadName = $(this).attr("name");
                    if (!$(this).val()) {
                        return;
                    }
                    data.field[uploadName] = eval($(this).val());
                    files = files.concat(eval($(this).val()));
                });

                return common.setFileLevel(files);
            },
            getCallback: function (data) {
                $("#tbxx").html("<span class='qbdms-TBinformation'>填报信息:</span><span class='qbdms-TBinformationText'>【" + data.data.filldept + " | " + data.data.fillman + " | " + data.data.filldate + "】</span>");
                disableNextElements(data.data.awardOrg);
                //-修改页面 初始化附件组件 开始 ------------------------------------------
                $('.uploadFileList').each(function () {
                    var fileUploadName = $(this).attr("fileUploadName");
                    var jsonFile = data.data[fileUploadName];
                    var files = eval(jsonFile);

                    if (files) {
                        for (var i = 0; i < files.length; i++) {
                            var fileLevel = files[i].fileLevel;
                            var fileLevelText = files[i].fileLevelText;
                            var fileSec = '<div class="fileSecLevel layui-input-inline">' + '<@secSelect.sec_select data_src=1 hasBlank=false/>' + "</div>";
                            var newStr = '<span class="file-id" style="margin-right: 20px;" fileId=' + files[i].fileId + ' fileLevelText="' + fileLevelText + '">' + fileSec + '<span class="file-name" title="点击下载文件" onclick="downFile(this)"><i class="iconfont data-iconcommon_fujian" style="margin-right: 5px"></i>' + files[i].fileName + '</span><i class="iconfont data-iconcommon_close deleteFile" ></i></span>';
                            $(this).append(newStr);
                            $(this).find("select:last").val(fileLevel);
                        }
                    }
                });
                //-修改页面 初始化附件组件 结束 ------------------------------------------
            },
            updateCallback: function (data) {
                if (publicMethods._filterRecord(data)) {
                    if ($(".privateSubmit")) {
                        $(".privateSubmit").attr("disabled", false).css("pointer-events", "auto");
                    }
                    layer.alert(publicMethods.confirmStyle(data.msg), {title: false, skin: 'confirm-class'}, function (index) {
                        layer.close(index);
                        window.location.href = serverPath.qbdmsPath + '/qbdms/wQbdAwardInformation/view/list';
                    });
                } else {
                    layer.alert(publicMethods.confirmStyle(data.msg), {title: false, skin: 'confirm-class'});
                }
                return false;
            }

        });

        //下载附件
        window.downFile = function (obj) {
            var fileId = $(obj).parents("span").attr("fileId");
            window.location.href = serverPath.qbdmsPath + setter.extendLinkPath + "attachFile/download?fileId=" + fileId;
        }

        // 删除
        $(document).on('click', '.deleteFile', function () {
            $(".uploadFileList").each(function (i, v) {
                common.constructFileStr(v)
            });
        });

        $('#selectAwardPersonBtn').click(function () {
            var userSelectorWin;
            var body;
            var layerH = publicMethods.layHeight('.listBody');
            layer.open({
                type: 2,
                title: '人员选择器',
                btn: ["保存", "取消", "撤销"],
                area: ['80%', layerH],
                skin: 'qbdms-layerFormBtn',
                btnAlign: 'c',
                content: "${ctx}/extend/dialog/view/singleSysUserDialogTenTree",
                success: function (layero, index) {
                    body = layer.getChildFrame('body', index);
                    userSelectorWin = window[layero.find('iframe')[0]['name']];
                },
                yes: function (index, layero) {
                    //执行iframe页的save方法
                    userSelectorWin.saveData(index);
                    var theUserList = body.find("input[name=selectUser]").val();
                    if (theUserList) {
                        var item = JSON.parse(theUserList);
                        var userName = item.fullName;
                        var account = item.account;
                        var orgName = item.orgName;
                        $("input[name='awardPerson']").val(userName);
                        $("input[name='awardPersonId']").val(account);
                        $("input[name='workDept']").val(orgName);
                    }
                    layer.close(index);
                },
                btn3: function (index, layero) {
                    userSelectorWin.cancelData(index);
                    return false //开启该代码可禁止点击该按钮关闭
                }
            })
        });

        form.on('select(awardOrg)', disableNextElements);
        // 页面初始化默认禁用获奖人，待选择个人/单位后根据情况启用
        $("input[name='awardPerson']").addClass("isReadonlyInput");
        $("#selectAwardPersonBtn").attr("disabled", true);

        function disableNextElements(element) {
            var val = element.value ? element.value : element;
            var orgName = "${orgName}";
            var code = "${code}";
            if (val === "个人") {
                // 允许选择获奖人
                $("#selectAwardPersonBtn").attr("disabled", false);
                // 获奖单位清空
                $("input[name='awardDept']").val("");
                $("input[name='awardDeptCode']").val("");
                // 获奖人、工作单位显示
                $("input[name='awardPerson']").attr("disabled", false);
                $("input[name='awardPerson']").removeClass("isReadonlyInput");
                $("input[name='workDept']").attr("disabled", false);
            } else if (val === "单位") {
                // 禁止选择获奖人
                $("#selectAwardPersonBtn").attr("disabled", true);
                // 获奖单位赋值
                $("input[name='awardDept']").val(orgName);
                $("input[name='awardDeptCode']").val(code);
                // 获奖人、工作单位置灰
                $("input[name='awardPerson']").attr("disabled", true);
                $("input[name='awardPerson']").val("");
                $("input[name='awardPerson']").addClass("isReadonlyInput");
                $("input[name='awardPersonId']").val("");
                $("input[name='workDept']").attr("disabled", true);
                $("input[name='workDept']").val("");
                $("input[name='workDeptCode']").val("");
            }
            form.render();
        }

        publicMethods.bottomFixd()
        form.on('select', function (data) {
            publicMethods.bottomFixd()
        });
        form.render();
    });
</script>
</body>
</html>